//
//  CLDocHeadImgCell.m
//  chanlin
//
//  Created by Ryan on 14-11-17.
//  Copyright (c) 2014年 chanlin. All rights reserved.
//

#import "CLDocHeadImgCell.h"
#import "UIImageView+WebCache.h"
#import "UIView+Utils.h"
#import "BlockUI.h"
#import "IFMoviePlayerController.h"


@implementation CLDocHeadImgCell


- (void)dealloc{
    if(self.pc){
         [[CLGloble sharedInstance] clearMovie];
    }
}

- (void)initUI{
    self.backgroundColor=self.backgroundColor=RGB(0xf8, 0xf8, 0xf8);
    self.headImage=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, GlobleWidth, (GlobleWidth*9.f)/16.f)];
    self.headImage.userInteractionEnabled=YES;
    [self addSubview:self.headImage];
    
}



- (void)loadImgUrl:(NSString *)url{
    [self.headImage sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:nil];
}

- (void)setIsSlider:(BOOL)isSlide itemId:(NSString *)itemId{
  
    if(isSlide){
        self.iconImageView=[[UIImageView alloc] init];
        self.iconImageView.frame=CGRectMake((self.headImage.width)-42.0f, CGRectGetHeight(self.headImage.frame)-22.0f, 42.0f, 22.0f);
        self.iconImageView.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleTopMargin;
        self.iconImageView.image=[UIImage imageNamed:@"doc_AtlasLabel.png"];
        
        [self.headImage addSubview:self.iconImageView];
        
    }else{
        [self.iconImageView removeFromSuperview];
        self.iconImageView=nil;
    }
}


- (void)setIsVideo:(BOOL)isvideo url:(NSString *)url{
    self.url=url;
    if(isvideo){
        if(!self.play){
            self.play=[UIButton buttonWithType:UIButtonTypeCustom];
            self.play.frame=CGRectMake(0, 0, 48, 48);
            [self.play setImage:[UIImage imageNamed:@"doc_playImage.png"] forState:UIControlStateNormal];
            [self.play setCenter:CGPointMake(self.headImage.width/2.f, self.headImage.height/2.f)];
            [self.headImage addSubview:self.play];
            
            __weak typeof(self) me=self;
            [self.play handleControlEvent:UIControlEventTouchUpInside withBlock:^(id sender) {
                if (me.url&& [me.url length] > 4){
                    [[CLGloble sharedInstance] clearMovie];
                    CGRect frame=self.superview.frame;
                    IFMoviePlayerController *moviePlayer = [[IFMoviePlayerController alloc] initWithContentURL:nil WithType:IFVideo_Type_Document];
                    //self.moviePlayer.delegate = self;
                    //self.moviePlayer.repeatMode = MPMovieRepeatModeOne;
                    
                    [moviePlayer.view setFrame:frame];
                    

                    [self.play.superview addSubview:moviePlayer.view];
                    
                    [moviePlayer setContentURL:[NSURL URLWithString:url]];
                    [moviePlayer prepareToPlay];
                    [moviePlayer play];
                    me.pc=moviePlayer;
                    [CLGloble sharedInstance].singleMovie=moviePlayer;

                    
                }
            }];
        }
    }else{
        if(self.play){
            [self.play removeFromSuperview];
            self.play=nil;
        }
    }
 
    
}


@end
